package service.network
{
	import service.interfaces.INetworkCommunication;

	/**
	 * NetworkFactory was created using the Factory and Singletone design patterns.
	 * 
	 * <p>
	 * It creates instances of INetworkCommunication and it's protected from instanciating. 
	 * </p>
	 */
	public class NetworkFactory
	{
		public static const HTTP:String = "HTTP";
		public static const XMPP:String = "XMPP";
		
		public function NetworkFactory(enforcer:SingletoneEnforcer) {
			if (enforcer == null) {
				throw new Error("Singletone may not be instanciated");
			}
		}
		
		/**
		 * Create an instance of INetworkCommunication.
		 * It returns null if the provided value is not a valid. 
		 */
		public static function createInstance(value:String):INetworkCommunication {
			switch (value) {
				case HTTP: {
					return new HTTPNetwork;
				}
				case XMPP: {
					return new XMPPNetwork;
				}
				default: {
					return null;
				}
			}
		}
	}
}

class SingletoneEnforcer {}